﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;

namespace broker.duty.ZDAL
{
    class Class1
    {
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Period == ppa.PolicyActing.PeriodActings.Count() - 1)
            {
                da.Value = ppa.Amount;

            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {

            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故"))
            {
                string s = ppa.PolicyActing.Policy.SelectedColRateFactors["年金领取年龄"];

                int a = Convert.ToInt32(s.Substring(0,2));

                int g = ppa.PolicyActing.Policy.SelectedInsurancePeriod.Value;

                int h = g - a;

                if (ppa.Age < a)
                {
                    da.Value = ppa.TotalFee * 1.1;

                }
                else
                {
                    double k = 0f;
                    double sum = 0f;
                    for (int i = 0; i <h; i++)
                    {
                        k = ppa.Amount * 1200 * Math.Pow(1.03, i);
                        sum += k;
                    }

                    da.Value = sum - ppa.GetDutyTotalValue("年金给付");
                }

                ppa.IsCurrentFinish = true;
            }

        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            string s = ppa.PolicyActing.Policy.SelectedColRateFactors["年金领取年龄"];

            int a = Convert.ToInt32(s);


            if (ppa.Age == a)
            {
                da.Value = ppa.Amount * 1200;
            }
            else if(ppa.Age >a)
            {
                IPolicyPeriodActing pppa = ppa.PolicyActing.PeriodActings[ppa.Period - 1];



                double v = pppa.DutyActings.FirstOrDefault(p => p.Duty.Name == "年金给付").Value;

                da.Value = v * 1.03;
            }


        }


        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故"))
            {
                if (ppa.Age <= 1)
                {
                    da.Value = ppa.Amount * 0.2;
                }
                else if (ppa.Age > 1 && ppa.Age <= 2)
                {
                    da.Value = ppa.Amount * 0.4;
                }
                else if (ppa.Age > 2 && ppa.Age <= 3)
                {
                    da.Value = ppa.Amount * 0.8;
                }
                else
                {
                    da.Value = ppa.Amount;
                }
                ppa.IsCurrentFinish = true;
            }
        }
    }
}
